package com.sky.controller.dish;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.Result;
import com.sky.service.DishServise;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/dish")
@Api(tags = "菜品相关接口")
public class DishController {
    @Autowired
    private DishServise dishServise;

    @PutMapping
    @ApiOperation("修改菜品信息")
    public Result edit(@RequestBody DishDTO dishDTO) {
        dishServise.editDish(dishDTO);
        return Result.success();

    }

    @PostMapping
    @ApiOperation("新增菜品")
    public Result save(@RequestBody DishDTO dishDTO) {
        dishServise.addDish(dishDTO);
        return Result.success();
    }

    @DeleteMapping
    @ApiOperation("批量删除菜品")
    public Result delete(@RequestParam("ids") List<Long> ids) {
        dishServise.deleteDish(ids);
        return Result.success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询菜品")
    public Result<DishDTO> selectById(@PathVariable Long id) {
        return Result.success(dishServise.list(id));
    }

    @GetMapping("/list")
    @ApiOperation("根据分类id查询菜品")
    public Result selectByCategoryId(Long categoryId) {
        return Result.success(dishServise.selectByCategoryId(categoryId));
    }

    @GetMapping("/page")
    @ApiOperation("分页查询菜品")
    public Result page(DishPageQueryDTO dishDTO) {
        return Result.success(dishServise.pageSelect(dishDTO));
    }

    @PostMapping("/status/{status}")
    @ApiOperation("启用禁用菜品")
    public Result startOrStop(@PathVariable Integer status, Long id) {
        dishServise.editStatus(id, status);
        return Result.success();
    }




}
